package com.lnu.information.thread;

/**
 * @author : jian.zhang-2
 * @description:
 * @date : Create in 3:02 PM 2022/5/12
 * @modified By :
 */
public class ClassRoom implements Runnable{

    Thread student,teacher;


    public ClassRoom() {
        teacher.setName("王老师");
        student.setName("张三");
    }

    @Override
    public void run() {
        if(Thread.currentThread() == student){
            try{
                System.out.println(student.getName() + "正在睡觉，不听课");
                Thread.sleep(1000*60*60);
            }catch (InterruptedException e){
                System.out.println(student.getName() + "被老师叫醒了");
            }
        }else if(Thread.currentThread() == teacher){
            for(int i = 1; i <=3; i++){
                System.out.println("上课！");
                try {
                    Thread.sleep(1000);
                }catch (InterruptedException e){
                    System.out.println(e.getMessage());
                }
            }
        }
    }
}
